package com.lihui.连续最大和;

import java.util.Scanner;

public class ContinuousMaximumSum {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int m=sc.nextInt();
        int[] array=new int[m];
        for (int i = 0; i < array.length; i++) {
            array[i] = sc.nextInt();
        }
        int sum=0;
        int i=0;
        while (i + 1 < m){
            int j=i+1;
            if (array[i]+array[j]>=sum){
                sum +=array[i]+array[j];
            }
            i++;
        }
        System.out.println(sum);
    }
}
